from base.tools.develop_tools import Singleton
from base.config.mongo_config import MongoConfig
import pymongo


class Mongodb(metaclass=Singleton):
    def __init__(self):
        self.client = pymongo.MongoClient(
            host=MongoConfig.HOST,
            port=MongoConfig.PORT,
            username=MongoConfig.USERNAME,
            password=MongoConfig.PASSWORD,
            authSource=MongoConfig.AUTHSOURCE,
        )
        self.db = self.client[MongoConfig.DBNAME]

    def __getitem__(self, table_name):
        return self.db[table_name]
    
    @property
    def table_list(self):
        return self.client.list_database_names()
